<?php

namespace app\admin\controller;

use tian\Controller;
use tian\Request;
use tian\Session;
use think\facade\Db;

class Base extends Controller
{
	protected $request;
    protected $infoAdmin;
	
    public function _before_action(): void
    {
		$isLogin = Session::has('id');
        if($isLogin==false){
            redirect('/admin/index/index');
        }
		
		$this->request = Request::instance();
		
		//赋值当前菜单
        if (method_exists($this, '_infoModule')) {
            $this->assign('infoModule', $this->_infoModule());
        }
		
		$this->getUserInfo();
		
		$this->getConfig();
    }
	
	//获取系统配置
    public function getConfig()
    {
        $infoConfig = model('AdminConfig')->getInfo();
        $this->sysConfig = $infoConfig;
        $this->assign('infoConfig', $infoConfig);
    }
	
	//登录信息
    public function getUserInfo()
    {
        $admin_id = Session::get('id');
        
        //获取用户信息
        $infoAdmin = Db::name('admin')->where('id',$admin_id)->find();
        $this->assign('infoAdmin',$infoAdmin);
        $this->infoAdmin = $infoAdmin;
    }
	
}